home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / program / progem.arc / gem6.asc < prev    next >
Text File  |  1987-10-10  |  21KB  |  434 lines

  1.                         *PROFESSIONAL GEM*
  2.                            by Tim Oren
  3.                   Column #6 - Raster operations
  4.  
  5.                         SEASONS GREETINGS!
  6.  
  7.      This is the Yuletide installment of ST PRO GEM, devoted to
  8. explaining the raster, or "bit-blit" portion of the Atari ST's VDI
  9. functions.
  10.  
  11.      Please note that this is NOT an attempt to show how to write
  12. directly to the video memory, although you will be able to deduce a
  13. great deal from the discussion.
  14.  
  15.      As usual, there is a download with this column.  You will find
  16. it in ATARI16 (PCS-58) in DL3 under the name of GEMCL6.C.
  17.  
  18.                           DEFINING TERMS
  19.  
  20.      To understand VDI raster operations, you need  to understand the
  21. jargon used to describe them.  (Many programmers will be tempted to
  22. skip this section and go directly to the code.  Please don't do it
  23. this time:  Learning the jargon is the larger half of understanding
  24. the raster operations!)
  25.  
  26.      In VDI terms a raster area is simply a chunk of contiguous words
  27. of memory, defining a bit image.  This chunk is called a "form".  A
  28. form  may reside in the ST's video map area or it may be in the data
  29. area of  your application.  Forms are roughly analogous to "blits" or
  30. "sprites"  on other systems.  (Note, however, that there is no sprite
  31. hardware on the ST.)
  32.  
  33.      Unlike other systems, there is NO predefined organization of the
  34. raster form.  Instead, you determine the internal layout of the form
  35. with an auxiliary data structure called the MFDB, or Memory Form
  36. Definition Block.  Before going into the details of the MFDB, we need
  37. to look at the various format options.  Their distinguishing features
  38. are monochrome vs. color, standard vs. device-specific and even-word
  39. vs. fringed.
  40.  
  41.                        MONOCHROME VS. COLOR
  42.  
  43.      Although these terms are standard, it might be better to say
  44. "single-color vs. multi-color".  What we are actually defining is the
  45. number of bits which correspond to each dot, or pixel, on the screen.
  46. In the ST, there are three possible answers. The high-resolution mode
  47. has one bit per pixel, because there is only one "color": white.
  48.  
  49.      In the medium resolution color mode, there are four possible
  50. colors for each pixel.  Therefore, it takes two bits to represent
  51. each dot on the screen.  (The actual colors which appear are
  52. determined by  the settings of the ST's pallette registers.)
  53.  
  54.      In the low resolution color mode, sixteen colors are generated,
  55. requiring four bits per pixel.  Notice that as the number of bits per
  56. pixel has been doubled for each mode, so the number of pixels on the
  57. screen has been halved: 640 by 400 for monochrome, 640 by 200 for
  58. medium-res, and 320 by 200 by low-res.  In this way the ST always
  59. uses  the same amount of video RAM: 32K.
  60.  
  61.      Now we have determined how many bits are needed for each pixel,
  62. but not how they are laid out within the form.  To find this out, we
  63. have  to see whether the form is device-dependent or not.
  64.  
  65.                STANDARD VS. DEVICE-SPECIFIC FORMAT
  66.  
  67.      The standard raster form format is a constant layout which is
  68. the same for all GEM systems.  A device-specific form is one which is
  69. stored in the internal format of a particular GEM system.  Just as
  70. the ST has three different screen modes, so it has three different
  71. device-specific form formats.  We will look at standard form first,
  72. then the ST-specific forms.
  73.  
  74.      First, it's reasonable to ask why a standard format is used. Its
  75. main function is to establish a portability method between various
  76. GEM systems.  For instance, an icon created in standard format on an
  77. IBM PC GEM setup can be moved to the ST, or a GEM Paint picture from
  78. an AT&T 6300 could be loaded into the ST version of Paint.
  79.  
  80.      The standard format has some uses even if you only work with the
  81. ST, because it gives a method of moving your application's icons and
  82. images amongst the three different screen modes.  To be sure,  there
  83. are limits to this.  Since there are different numbers of pixels  in
  84. the different modes, an icon built in the high-resolution mode will
  85. appear twice as large in low-res mode, and would appear oblong in
  86. medium-res.  (You can see this effect in the ST Desktop's icons.)
  87. Also,  colors defined in the lower resolutions will be useless in
  88. monochrome.
  89.  
  90.      The standard monochrome format uses a one-bit to represent
  91. black, and uses a zero for white.  It is assumed that the form begins
  92. at the  upper left of the raster area, and is written a word at a
  93. time left to right on each row, with the rows being output top to
  94. bottom.  Within each word, the most significant bit is the left-most
  95. on the screen.
  96.  
  97.      The standard color form uses a storage method called "color
  98. planes". The high-order bits for all of the pixels are stored just as
  99. for monochrome, followed by the next-lowest bit in another contiguous
  100. block, and so on until all of the necessary color bits have been
  101. stored.
  102.  
  103.      For example, on a 16-color system, there would be four different
  104. planes.  The color of the upper-leftmost bit in the form would be
  105. determined by concatenating the high-order bit in the first word of
  106. each plane of the form.
  107.  
  108.      The system dependent form for the ST's monochrome mode is very
  109. simple: it is identical to the standard form!  This occurs because
  110. the  ST uses a "reverse-video" setup in monochrome mode, with the
  111. background  set to white.
  112.  
  113.      The video organization of the ST's color modes is more
  114. complicated. It uses an "interleaved plane" system to store the bits
  115. which make up a pixel.  In the low-resolution mode, every four words
  116. define the values of 16 pixels.  The high-order bits of the four
  117. words are merged to form the left-most pixel, followed by the next
  118. lower bit of each word, and so on.  This method is called
  119. interleaving because the usually separate color planes described
  120. above have been shuffled together in memory.
  121.  
  122.      The organization of the ST's medium-resolution mode is similar
  123. to low-res, except the only two words are taken at a time.  These are
  124. merged to create the two bits needed to address four colors.
  125.  
  126.      You should note that the actual color produced by a particular
  127. pixel value is NOT fixed.  The ST uses a color remapping system
  128. called a palette.  The pixel value in memory is used to address a
  129. hardware  register in the palette which contains the actual RGB
  130. levels to be sent to the display.  Programs may set the palette
  131. registers with  BIOS calls, or the user may alter its settings with
  132. the Control Panel desk accessory.  Generally, palette zero
  133. (background) is left as white, and the highest numbered palette is
  134. black.
  135.  
  136.                       EVEN-WORD VS. FRINGES
  137.  
  138.      A form always begins on a word boundary, and is always stored
  139. with an integral number of words per row.  However,  it is possible
  140. to use only a portion of the final word.  This partial word is called
  141. a "fringe".  If, for instance, you had a form 40 pixels wide,  it
  142. would be stored with four words per row: three whole words, and one
  143. word with the eight pixel fringe in its upper byte.
  144.  
  145.                               MFDBs
  146.  
  147.      Now we can intelligently define the elements of the MFDB.  Its
  148. exact C structure definition will be found in the download. The
  149. fd_nplanes entry determines the color scheme: a value of one is
  150. monochrome, more than one denotes a color form.  If fd_stand is zero,
  151. then the form is device-specific, otherwise it is in standard format.
  152.  
  153.      The fd_w and fd_h fields contain the pixel width and height of
  154. the form respectively.  Fd_wdwidth is the width of a row in words.
  155. If fd_w is not exactly equal to sixteen times fd_wdwidth, then the
  156. form has a fringe.
  157.  
  158.      Finally, fd_addr is the 32-bit memory address of the form
  159. itself. Zero is a special value for fd_addr.  It denotes that this
  160. MFDB is for the video memory itself.  In this case, the VDI
  161. substitutes the actual address of the screen, and it ignores ALL of
  162. the other parameters. They are replaced with the size of the whole
  163. screen and number of planes in the current mode, and the form is (of
  164. course) in device-specific format.
  165.  
  166.      This implies that any MFDB which points at the screen can only
  167. address the entire screen.  This is not a problem, however, since t